package chapter11;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-23 上午10:32
 */
public class InputTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(InputTest.class);

    public static void main(String[] args) {
        boolean flag = true;
        try (InputStream inputStream = System.in;
             ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            while (flag) {
                System.out.println("Please input data:");
                int temp = 0;
                while ((temp = inputStream.read()) != -1) {
                    if (temp == '\n') {
                        break;
                    }
                    out.write(temp);
                }
                String input = new String(out.toByteArray());
                if ("q".equals(input)) {
                    System.out.println("Quit...");
                    flag = false;
                } else {
                    System.out.println("input data:" + input);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
